package com.fcx.workai.home_module.util;

import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.List;
import java.util.RandomAccess;

/**
 * Created by hxh on 2018/5/22.
 */

public class CollectionsUtil {
    private static final Collection NULL_COLLECTION = new NullCollection();

    public static final <T> Collection<T> nullCollection() {
        return (List<T>) NULL_COLLECTION;
    }

    public static class NullCollection extends AbstractList<Object>
            implements RandomAccess, Serializable {

        private static final long serialVersionUID = 5206887786441397812L;

        @Override
        public Object get(int index) {
            return null;
        }

        @Override
        public int size() {
            return 1;
        }

        public boolean contains(Object obj) {
            return null == obj;
        }

        private Object readResolve() {
            return null;
        }
    }

}
